package controller.avonigo.com;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.URL;
import java.util.logging.Logger;

import tools.avonigo.com.Constantes;


public class LocationController {

	private static final Logger log = Logger.getLogger(LocationController.class.getName());
	public static String getLocation(String ip) throws Exception{
		
		URL link = new URL(Constantes.FREEGEOIP+ip);

		BufferedReader in = null;
		try {
			in = new BufferedReader(new InputStreamReader(link.openStream()));
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		String inputLine;
		StringBuilder builder = new StringBuilder();
		while ((inputLine = in.readLine()) != null){
			builder.append(inputLine);
			log.info(inputLine);
		}
		in.close();
		return builder.toString();
	}
}
